package com.service.EasyExcel.Service.Impl;

import com.EasyExcel.api.ExcelImportVO;
import com.alibaba.excel.EasyExcel;
import com.service.EasyExcel.Mapper.FilteringRulesMapper;
import com.service.EasyExcel.Service.FilteringRulesService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;


/**
 * @author lqj
 * @version 1.0
 * @description:
 * @date 2022/5/15 10:06
 */
@Service
public class FilteringRulesServiceImpl implements FilteringRulesService {

    @Autowired
    private FilteringRulesMapper filteringRulesMapper;

    @Override
    public void importUserExcel(MultipartFile file) throws Exception {

        List<ExcelImportVO> excelImportVOList = EasyExcel.read(file.getInputStream()).sheet(0).head(ExcelImportVO.class).headRowNumber(1).doReadSync();

        if (CollectionUtils.isEmpty(excelImportVOList)) {
            excelImportVOList.forEach(excelImportVO -> {
                ExcelImportVO excelImportVO1 = new ExcelImportVO();
                //获取文件内容
                excelImportVO1.setUserName(excelImportVO.getUserName());
                excelImportVO1.setNickName(excelImportVO.getNickName());
                excelImportVO1.setEMail(excelImportVO.getEMail());
                excelImportVO1.setTelephone(excelImportVO.getTelephone());
                excelImportVO1.setDepartment(excelImportVO.getDepartment());
                excelImportVO1.setRoleName(excelImportVO.getRoleName());

                filteringRulesMapper.insertUserinfo(excelImportVO);

            });
        }


    }
}
